﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace EbmtDAL
{
    /// <summary>
    /// This is a customised DataAdapter class which will be used to load only data that is needed.
    /// Needed data are identified by ID and IDAA primary keys.
    /// </summary>
    public class EbmtDataAdapter : System.ComponentModel.Component
    {
        private System.Data.SqlClient.SqlDataAdapter _adapter;
        private System.Data.SqlClient.SqlCommand[] _commandCollection;
        private bool _clearBeforeFill;
        private string _tableName;
        private bool _idIdaaKeysExist;

        public System.Data.SqlClient.SqlDataAdapter Adapter
        {
            get
            {
                return this._adapter;
            }
            set
            {
                this._adapter=value;
            }
        }

        public System.Data.SqlClient.SqlCommand[] CommandCollection
        {
            get
            {
                return this._commandCollection;
            }
            set
            {
                this._commandCollection=value;
            }
        }

        public bool ClearBeforeFill
        {
            get
            {
                return this._clearBeforeFill;
            }
            set
            {
                this._clearBeforeFill = value;
            }
        }

        public bool IdIdaaKeysExist
        {
            get
            {
                return this._idIdaaKeysExist;
            }
            set
            {
                this._idIdaaKeysExist = value;
            }
        }

        public string TableName
        {
            get
            {
                return _tableName;
            }
            set
            {
                _tableName = value;
            }
        }

        public EbmtDataAdapter(SqlDataAdapter dAdapter, System.Data.SqlClient.SqlCommand[] commandCollection)
        {
            this.ClearBeforeFill = true;
            Adapter = dAdapter;
            CommandCollection = commandCollection;
        }

        //[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
        [global::System.ComponentModel.DataObjectMethodAttribute(global::System.ComponentModel.DataObjectMethodType.Fill, true)]
        public virtual int FillByIDIDAA(DataTable dataTable, int ID, int IDAA)
        {
            this.Adapter.SelectCommand = this.CommandCollection[1];
            this.Adapter.SelectCommand.Parameters[0].Value = ((int)(ID));
            this.Adapter.SelectCommand.Parameters[1].Value = ((int)(IDAA));
            if ((this.ClearBeforeFill == true))
            {
                dataTable.Clear();
            }
            int returnValue = this.Adapter.Fill(dataTable);
            return returnValue;
        }

        //[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
        [global::System.ComponentModel.DataObjectMethodAttribute(global::System.ComponentModel.DataObjectMethodType.Fill, true)]
        public virtual int Fill(DataTable dataTable)
        {
            this.Adapter.SelectCommand = this.CommandCollection[0];
            if ((this.ClearBeforeFill == true))
            {
                dataTable.Clear();
            }
            int returnValue = this.Adapter.Fill(dataTable);
            return returnValue;
        }
    }
}
